<?php 
if($type == 'sent')
{
	$headerUserToShow = 'Recipient';
	$userId = 'recipient_id';
	$username = 'recipient_username';
	$userSlug = 'recipient_slug';
} else {
	$headerUserToShow = 'Sender';
	$userId = 'sender_id';
	$username = 'sender_username'; 
	$userSlug = 'sender_slug';
}
?>
<div class="messages index">

<div class="fr">
	<?php echo $this->element('messagesTop',array('plugin'=>'messages'));?>
</div>
<h4>
<?php
if(is_array($messages) && count($messages)>0)
{
		echo $paginator->counter(array(
		'format' => __('%count% messages found', true)
		));
?></h4>
<?php echo $form->create('Message', array('action'=>'delete'));?>
<table cellpadding="0" cellspacing="0" class="table">
	<tr>
		<th>
			<input type='checkbox' name='checkAll' id="checkAll" onclick="toggleCheckboxes($('.message_input'));">
		</th>
		<th width="40%"><?php echo __("Subject")?></th>
		<th><?php echo __($headerUserToShow);?></th>
		<th><?php echo __("Date")?></th>
		<th><?php echo __("Action")?></th>
	</tr>
	<?php
	$i = 0;
	foreach ($messages as $message):
//prd($message);
	$class = null;
	if ($i++ % 2 == 0) {
		$class = ' class="altrow"';
	}
	?>
	<tr<?php echo $class;?>>
		
		<td>	
			<?php echo $form->input('message_'.$message['Message']['id'], array('label'=>'', 'type'=>'checkbox', 'class'=>'message_input')); ?>
		</td>
		<td>
			<?php echo $html->link($message['Message']['subject'], '/messages/view/'.$message['Message']['id'].'/type:'.$type); ?>
		</td>
		<td>
			<?php echo $html->link(ucfirst($message['Message'][$username]),'/users/profile/'.$message['Message'][$userSlug]);?>			
		</td>
		<td>
			<?php echo $time->nice($message['Message']['created']); ?>
		</td>
		<td>
			<?php echo $html->link(__('Delete'), '/messages/delete/'.$message['Message']['id'].'/type:'.$type,null,sprintf(__('Are you sure, you want to delete this message?'))); ?>
		</td>		
	</tr>
	<?php endforeach; ?>

</table>

<div class="paging">
	<?php echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?>
 | 	<?php echo $paginator->numbers();?>
	<?php echo $paginator->next(__('next', true).' >>', array(), null, array('class'=>'disabled'));?>
</div>
<?php echo $form->end(__('Delete'));?>
<?php   } else { ?>
	<?php echo "<h4 class='no_results'>".__("Sorry, no messages found.")."</h4>"?>
<?php  } ?>
</div>